-- 创建主框架
local debuffFrame = CreateFrame("Frame", "SerpentStingTracker", UIParent)
debuffFrame:SetSize(200, 60)
debuffFrame:SetPoint("CENTER", 0, 150)

-- 背景
local bg = debuffFrame:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints(true)
bg:SetColorTexture(0.1, 0.1, 0.2, 0.7)

-- 边框
local border = debuffFrame:CreateTexture(nil, "BORDER")
border:SetPoint("TOPLEFT", -3, 3)
border:SetPoint("BOTTOMRIGHT", 3, -3)
border:SetColorTexture(0.3, 0.3, 0.5, 0.5)

-- 标题文本
local title = debuffFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOP", 0, -10)
title:SetText("毒蛇钉刺检测")
title:SetTextColor(1, 0.8, 0)

-- 状态文本
local statusText = debuffFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
statusText:SetPoint("CENTER", 0, 10)
statusText:SetText("无目标")

-- 注册事件
debuffFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
debuffFrame:RegisterEvent("UNIT_AURA")
debuffFrame:SetScript("OnEvent", function(self, event, unit)
    if event == "PLAYER_TARGET_CHANGED" then
        self:UpdateStatus()
    elseif event == "UNIT_AURA" and unit == "target" then
        self:UpdateStatus()
    end
end)

-- 检测目标毒蛇钉刺功能
debuffFrame.UpdateStatus = function(self)
    -- 重置状态
    local hasDebuff = false
    local text = "无目标"

    if UnitExists("target") then
        local targetName = UnitName("target")
        text = targetName.."无毒蛇钉刺"

        -- 检查目标身上是否有毒蛇钉刺debuff (使用法术ID 87935)
        for i = 1, 40 do
            local name, _, count, _, duration, expiration, source, _, _, spellId = UnitDebuff("target", i)
            if not name then break end

            -- 熊猫人之谜毒蛇钉刺法术ID是87935
            if spellId == 87935 then
                local remaining = expiration - GetTime()
                if remaining > 0 then
                    text = string.format("%s毒蛇钉刺: %.1f秒", targetName, remaining)
                    hasDebuff = true
                    break
                end
            end
        end
    end

    -- 更新文本显示
    statusText:SetText(text)

    -- 根据状态设置文本颜色
    if hasDebuff then
        statusText:SetTextColor(0, 1, 0) -- 绿色：有debuff
    elseif UnitExists("target") then
        statusText:SetTextColor(1, 0, 0) -- 红色：有目标但无debuff
    else
        statusText:SetTextColor(0.8, 0.8, 0.8) -- 灰色：无目标
    end
end

-- 添加拖动功能
debuffFrame:SetMovable(true)
debuffFrame:EnableMouse(true)
debuffFrame:SetClampedToScreen(true)
debuffFrame:RegisterForDrag("LeftButton")

debuffFrame:SetScript("OnDragStart", debuffFrame.StartMoving)
debuffFrame:SetScript("OnDragStop", debuffFrame.StopMovingOrSizing)

-- 初始更新
debuffFrame:UpdateStatus()

-- 打印说明
print("目标毒蛇钉刺检测框已创建")
print(" - 拖动：鼠标左键")
print(" - 目标身上有毒蛇钉刺会显示剩余时间")
print(" - 绿色：有debuff，红色：无debuff，灰色：无目标")